'''
Created on Apr 11, 2012

@author: Johnathon
'''
from Gates.ANDGate import AndGate
from Gates.NANDGate import NandGate
from Wire import Wire
import sys
import unittest
import util
import pprint

class Test(unittest.TestCase):


    def setUp(self):
        self.input1 = Wire("input1", 0, None, [])
        self.input11 = Wire("input11", 0, self.input1, [])
        self.input12 = Wire("input12", 0, self.input1, [])
        self.input1.destinations = [self.input11, self.input12]
        
        self.input2 = Wire("input2", 0, None, [])
        self.input21 = Wire("input21", 0, self.input2, [])
        self.input22 = Wire("input22", 0, self.input2, [])
        self.input2.destinations = [self.input21, self.input22]
        
        self.middleOut = Wire("middleOut", 1, None, [])
        self.middle1 = Wire("middle1", 1, self.middleOut, [])
        self.middle2 = Wire("middle2", 1, self.middleOut, [])
        self.middleOut.destinations = [self.middle1, self.middle2]
        
        self.topOut = Wire("topOut", 1, None, [])
        self.bottomOut = Wire("bottomOut", 1, None, [])
        self.output = Wire("output", 2, None, [])
        
        self.middleNAND = NandGate("middleNAND", 1, [self.input11, self.input21], self.middleOut)
        self.topNAND = AndGate("topNAND", 2, [self.input12, self.middle1], self.topOut)
        self.bottomNAND = NandGate("bottomNAND", 2, [self.input22, self.middle2], self.bottomOut)
        self.lastNAND = AndGate("lastNAND", 3, [self.bottomOut, self.topOut], self.output)
        
        self.gates = [[self.middleNAND], [self.bottomNAND, self.topNAND], [self.lastNAND]]
        self.lines = [[self.input1, self.input11, self.input12, self.input2, self.input21, self.input22, self.middleOut, self.middle1, self.middle2, self.topOut, self.bottomOut, self.output]]

        self.pp = pprint.PrettyPrinter(indent=4)

    def tearDown(self):
        pass


    def test(self):
        output = util.collapseFaults(self.gates, self.lines)
        for i in output:
            self.pp.pprint(i)
#            if isinstance(i, list):
#                sys.stdout.write('[')
#                for x in i:
#                    sys.stdout.write("(%s, %s), " % (x[0], x[1].__repr__()))
#                sys.stdout.write("]\n")
#            else:
#                print "(%s, %s)" % (i[0], i[1].__repr__())
        self.assertTrue(True)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()